let id = Math.ceil(Math.random() * 10);
/* function getCode(){
				$("#codeImg").attr('src','http://bzr7kz.natappfree.cc/kapt?clientId=' + id);
			} */
//getCode();
// 二次密码校验
function confirm() {
  let password = $("#password").val(),
    confirmPsd = $("#confirmPsd").val();
  if (!password || !password.trim()) {
    mui.alert($("#password").attr("placeholder"));
  } else if (!confirmPsd || !confirmPsd.trim()) {
    mui.alert($("#confirmPsd").attr("placeholder"));
  } else if (password !== confirmPsd) {
    mui.alert("两次密码输入不一致,请重新输入");
  }
}
$("#registerBtn").click(function () {
  let username = $("#username").val(),
    mobile = $("#phone").val(),
    zname = $("#zname").val(),
    nickname = $("#nickname").val(),
    //inUserId = $("#inUserId").val(),
    password = $("#password").val();
  // 校验
  let check = true;
  $(".verify").each(function (index, element) {
    if (!$(this).val() || !$(this).val().trim()) {
      // 是否未填
      mui.alert($(this).attr("placeholder"));
      check = false;
      return false;
    } else {
      // 格式校验
      if (index == 1) {
        // 手机号码格式
        let reg_tel = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
        if (!reg_tel.test($(this).val())) {
          mui.alert("请填写正确的手机号码");
          check = false;
          return false;
        }
      }
    }
  });
  if (check) {
    let user = {
      userName: username,
      mobile: mobile,
      zname: zname,
      name: nickname,
      inUserId: new acquire().parameterMap["userId"],
      password: password,
    };
    $.ajax({
      url: server + "/v1/api/users/regist",
      data: JSON.stringify(user),
      dataType: "json",
      type: "post",
      processData: false,
      headers: { "Content-Type": "application/json" },
      success: function (res) {
        if (res.code == 200) {
          mui.alert("注册成功");
          location.href =
            "http://down.mtxc3.org/downpage/986441ea18594bda";
        } else {
          mui.alert(res.msg);
        }
      },
      error: function (err) {
        mui.alert("注册失败");
      },
    });
  }
});
